home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
gnulib
/
libsrc98.zoo
/
dup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-01
|
878b
|
45 lines
/* from Dale Schumacher's dLibs library */
/* these will have to be adjusted at some time ++jrb */
/* use these with caution, TOS 1.4 still has double re-direction bug! */
#include <stddef.h>
#include <unistd.h>
#include <fcntl.h>
#include <osbind.h>
#include <errno.h>
#include "lib.h"
int dup(handle)
int handle;
{
register int rv;
rv = Fdup(handle);
if(( rv < (__SMALLEST_VALID_HANDLE)) ||
(__OPEN_INDEX(rv) >= __NHANDLES) ) {
errno = -rv; rv = -1;
} else {
__open_stat[__OPEN_INDEX(rv)] =
__open_stat[__OPEN_INDEX(handle)];
}
return(rv);
}
int dup2(handle1, handle2)
int handle1, handle2;
{
int rv;
close(handle2);
rv = Fforce(handle2, handle1);
if ((rv < 0) ||
(__OPEN_INDEX(handle2) >= __NHANDLES))
errno = -rv;
else
__open_stat[__OPEN_INDEX(handle2)] =
__open_stat[__OPEN_INDEX(handle1)];
return (rv < 0) ? -1 : handle2;
}